<?php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap {

	public function _initAutoload() {
		$loaderModel = new Zend_Loader_Autoloader_Resource(array(
					'basePath' => APPLICATION_PATH . '/models',
					'namespace' => 'Model',
				));
		$loaderModel->addResourceType('dbtable', 'DbTable', 'DbTable')
				->addResourceType('row', 'Row', 'Row')
				->addResourceType('rowset', 'Rowset', 'Rowset');
		unset($loaderModel);

		$loaderLibrary = new Zend_Loader_Autoloader_Resource(array(
					'basePath' => PATH_LIB,
					'namespace' => '',
				));
		$loaderLibrary->addResourceType('bvb', 'Bvb', 'Bvb');
		unset($loaderLibrary);

		$loaderLib2 = new Zend_Loader_Autoloader_Resource(array(
					'basePath' => PATH_ZFEXTEND,
					'namespace' => '',
				));
		$loaderLib2->addResourceType('ZFKiller', 'ZFKiller', 'ZFKiller')
				->addResourceType('ZFWork', 'ZFWork', 'ZFWork')
		;
		unset($loaderLib2);

		$loaderModules = new Zend_Loader_Autoloader_Resource(array(
					'basePath' => APPLICATION_PATH . '/modules',
					'namespace' => '',
				));
		$loaderModules->addResourceType('work', 'work', 'Work');
		$loaderModules->addResourceType('site', 'site', 'Site');
		unset($loaderModules);

		$loaderMy = new Zend_Loader_Autoloader_Resource(array(
					'basePath' => APPLICATION_PATH,
					'namespace' => '',
				));
		$loaderMy->addResourceType('My', 'My', 'My');
		unset($loaderMy);
	}

	/**
	 * Função faz a conexão com o banco de dados e registra a variável $db para
	 * que ela esteja disponível em toda a aplicação.
	 * @link http://www.danieldeveloper.com/2010/02/02/criando-conexao-com-banco-de-dados-usando-zend-framework/
	 */
	protected function _initConnection() {
		try {
			$db = Zend_Db::factory('pdo_mysql', array(
						'host' => 'localhost',
						'username' => 'root',
						'password' => 'teste',
						'dbname' => 'materialcontrol',
						'charset' => 'UTF8',
					));

			//$db->query("SET character_set_results = 'utf8', character_set_client = 'utf8', character_set_connection = 'utf8', character_set_database = 'utf8', character_set_server = 'utf8'");
			Zend_Db_Table::setDefaultAdapter($db);

			// Habilitar FirePHP
			$profiler = new Zend_Db_Profiler_Firebug('All DB Queries');
			$profiler->setEnabled(true);
			$db->setProfiler($profiler);

			unset($db);
		} catch (Zend_Exception $e) {
			echo "Estamos sem conexão ao banco de dados neste momento. Tente mais tarde por favor.";
			exit;
		}
	}

	protected function _initLocale() {
		Zend_Registry::set('Zend_Locale', new Zend_Locale(Zend_Locale::BROWSER));
		date_default_timezone_set('UTC');
	}

}